/**
 * futures : masterlink.futures.controller.IndexController.java
 */
package masterlink.futures.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import masterlink.futures.dao.RealTimeRateTXODao;
import masterlink.futures.util.WebUtils;
import masterlink.futures.vo.Employee;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * TODO Write the description
 *
 * @author : tonyyang
 * Create date : 2011/9/30
 * @version 1.0.0	
 */
@Controller
@RequestMapping(value = "/market")
public class MarketController extends BasicController{
	
	@Autowired
	@Qualifier("RealTimeRateTXODao")
	private RealTimeRateTXODao realTimeRateTXOdao;
	
	@RequestMapping(method=RequestMethod.GET)
	@Override
	public String index(HttpServletRequest req){
		Employee emp=WebUtils.getLogEmployee(req);
		log.trace("{} loading market data.",emp);
		List<String> all=realTimeRateTXOdao.findMonth();
		req.setAttribute("MONTHS", all);
		req.setAttribute("MONTH", all.get(0));
		req.setAttribute("ALL_DATA", realTimeRateTXOdao.findAll(all.get(0)));
		return "data/market";
	}
	
	@RequestMapping(value="/json/find",method=RequestMethod.GET)
	public String jsonFind(@RequestParam("term")String term,HttpServletRequest req){
		Employee emp=WebUtils.getLogEmployee(req);
		log.trace("{} finding json product id {}.",emp,term);
		req.setAttribute("data", realTimeRateTXOdao.findProdid(term));
		return "json/autoComplete";
	}
	
	@RequestMapping(value = "/find/{month}",method=RequestMethod.GET)
	public String find(@PathVariable("month")String month,HttpServletRequest req){
		Employee emp=WebUtils.getLogEmployee(req);
		log.trace("{} finding product by id {}.",emp,month);
		req.setAttribute("MONTHS", realTimeRateTXOdao.findMonth());
		req.setAttribute("MONTH", month);
		req.setAttribute("ALL_DATA", realTimeRateTXOdao.findAll(month));
		return "data/market";
	}
	
}
